package com.itema.mapper;

import com.itema.pojo.Emp;
import com.itema.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {
    /**
     * 查询所有的员工及其对应的部门名称
     */
    //@Select("select e.*, d.name deptName from emp as e left join dept as d on e.dept_id = d.id")
    public List<Emp> list(EmpQueryParam empQueryParam);

    /**
     * 添加员工
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into emp(username, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time) " +
            "values (#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    /**
     * 批量删除员工
     */
    void deleteByIds(List<Integer> ids);

    Emp findById(Integer id);


    void update(Emp emp);

    /**
     * 统计各个职位的员工人数
     */
    @MapKey("pos")//是 MyBatis 注解，用于指定将查询结果中的哪个字段作为 Map 的键(key)。
    List<Map<String,Object>> countEmpJobData();

    @MapKey("name")
    List<Map> countEmpGenderData();



    /**
     * 查询所有员工
     */
    @Select("select * from emp")
    List<Emp> findAll();


    @Select("select * from emp where username=#{username} and password=#{password}")
    Emp getUsernameAndPassword(Emp emp);
}


